package com.itbird.eventbus.core;

import android.os.Looper;

/**
 * 主线程操作支持类
 * Created by itbird on 2022/9/19
 */
public interface MainThreadSupport {
    //判断是否是当前线程
    boolean isMainThread();

    //实现主线程切换执行
    Poster createPoster(EventBus eventBus);

    class AndroidHandlerMainThreadSupport implements MainThreadSupport {

        private final Looper looper;

        public AndroidHandlerMainThreadSupport(Looper looper) {
            this.looper = looper;
        }

        @Override
        public boolean isMainThread() {
            return looper == Looper.myLooper();
        }

        @Override
        public Poster createPoster(EventBus eventBus) {
            return new HandlerPoster(eventBus, looper);
        }
    }
}
